﻿using System;
using System.Data.Entity;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Capacitacion.Models;

namespace Capacitacion
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "List",
                "List/{action}",
                new { controller = "List", action = UrlParameter.Optional }
            );

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
        }

        protected void Application_Start()
        {
            Database.SetInitializer(new ModelointegradorDbInitializer());

            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
    public class ModelointegradorDbInitializer : DropCreateDatabaseIfModelChanges<RestaurantsContext>
    {
        protected override void Seed(RestaurantsContext context)
        {
            base.Seed(context);

            context.People.Add(new Person
            {
                Nombre = "Mabel",
                Apellido = "Villaseco",
                NumDoc = 11325120,
                Genero = "F"
            });
            context.People.Add(new Person
            {
                Nombre = "Mauro",
                Apellido = "Villaseco",
                NumDoc = 35410479,
                Genero = "M"
            });

            context.Restaurants.Add(new Restaurant
            {
                Name = "MC Donald",
                Address = new Address
                {
                    AddressId = 0,
                    City = "Mar Del Plata",
                    State = "Buenos Aires",
                    Country = "Argentina"
                }
            });
            context.Restaurants.Add(new Restaurant
            {
                Name = "Burger King",
                Address = new Address
                {
                    AddressId = 1,
                    City = "Potosì",
                    State = "Misiones",
                    Country = "Argentina"
                }
            });
            context.Reviews.Add(new Review
            {
                Id = 1,
                Restaurant = "Burger King",
                Comment = "Great place",
                Created = DateTime.Now,
                Rating = 9
            });
            context.Reviews.Add(new Review
            {
                Id = 2,
                Restaurant = "MC Donald",
                Comment = "I Almost die!",
                Created = DateTime.Now,
                Rating = 3
            });
            context.SaveChanges();
        }
    }
}